package com.thread.thread.ThreadPool线程池;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
//定时执行的线程，arg1 运行的线程 arg2 延迟的时间 arg3 单位
public class ScheduledThreadpoolTest {
	static ScheduledExecutorService  scheduledExecutorService= Executors.newScheduledThreadPool(2);

	public static void main(String[] args) {

		scheduledExecutorService.schedule(() -> {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("延迟3秒执行1"+scheduledExecutorService);
		},3, TimeUnit.SECONDS);


		scheduledExecutorService.schedule(() -> {

			System.out.println("延迟3秒执行2"+scheduledExecutorService);
		},3, TimeUnit.SECONDS);
	}

}
